//
//  LOLMainViewController.m
//  LOLNews
//
//  Created by MXL on 16/10/28.
//  Copyright © 2016年 KK. All rights reserved.
//

#import "LOLMainViewController.h"

@interface LOLMainViewController ()

@end

@implementation LOLMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 界面
- (void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSMutableArray *conArrM = [NSMutableArray array];
    // 资讯
    [conArrM addObject:[self addControllerWithClassName:@"LOLNewsViewController" andTitle:@"英雄联盟" andImage:@"tab_icon_news_normal" andSelectImage:@"tab_icon_news_press"]];
    // 好友
    [conArrM addObject:[self addControllerWithClassName:@"LOLFriendsViewController" andTitle:@"好友" andImage: @"tab_icon_friend_normal" andSelectImage:@"tab_icon_friend_press"]];
    // 发现
    [conArrM addObject:[self addControllerWithClassName:@"LOLDiscoveryViewController" andTitle:@"发现" andImage:@"tab_icon_quiz_normal" andSelectImage:@"tab_icon_quiz_press"]];
    // 我的
    [conArrM addObject:[self addControllerWithClassName:@"LOLMineViewController" andTitle:@"我" andImage:@"tab_icon_more_normal" andSelectImage:@"tab_icon_more_press"]];
    // 添加进Main
    self.viewControllers = conArrM.copy;
    
}

#pragma mark - 重构添加 控制器
- (UINavigationController *)addControllerWithClassName:(NSString *)className andTitle:(NSString *)title andImage:(NSString *)imageName andSelectImage:(NSString *)selectImageName{
    // 创建类
    Class cla = NSClassFromString(className);
    // 断言
    NSAssert(![UIViewController isSubclassOfClass:cla], @"这不是控制器");
    
    UIViewController *vc = [[cla alloc]init];
    
    // 创建两个image
    UIImage *image = [UIImage imageNamed:imageName];
    UIImage *selectImage = [UIImage imageNamed:selectImageName];
    
    vc.title = title;
    
    vc.tabBarItem.image = image;
    
    vc.tabBarItem.selectedImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor cz_colorWithHex:0xBC985A]} forState:UIControlStateSelected];
    
    
    return [[UINavigationController alloc]initWithRootViewController:vc];
    
}
@end
